#include "main_interface.h"
#include "ui_main_interface.h"
#include <QPixmap>
#include <QPalette>
#include <QBrush>
#include <QResizeEvent>
#include <QDebug>

Main_interface::Main_interface(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Main_interface)
{
    ui->setupUi(this);

    // 设置窗口属性
    setAttribute(Qt::WA_StyledBackground);

    // 设置堆叠窗口部件的边距和透明背景
    ui->stackedWidget->setContentsMargins(0, 0, 0, 0);
    ui->stackedWidget->setStyleSheet("QStackedWidget { background: transparent; }");

    // 确保窗口本身也没有边距
    this->setContentsMargins(0, 0, 0, 0);

    // 加载背景图片
    background = QPixmap(BEIJING);

    // 移除删除my_car页面的代码，保留原有的页面结构
}


Main_interface::~Main_interface()
{
    delete ui;
}

// 添加 resizeEvent 处理
void Main_interface::resizeEvent(QResizeEvent *event)
{
    QWidget::resizeEvent(event);
    updateBackground();
}

void Main_interface::updateBackground()
{
    if(!background.isNull()) {
        QPixmap scaled = background.scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

        // 使用样式表设置背景
        QString style = QString("Main_interface { border-image: url(%1) 0 0 0 0 stretch stretch; }")
                       .arg(BEIJING);
        this->setStyleSheet(style);
    }
}



void Main_interface::on_Air_PushButton_clicked()
{
    if (ui->my_car) {
            ui->stackedWidget->setCurrentWidget(ui->my_car);
        } else {
            qDebug() << "My_Car界面未找到";
        }

}
void Main_interface::on_Monitoring_PushButton_clicked()
{
    // 切换到 Parking_Surveillance 页面
    ui->stackedWidget->setCurrentWidget(ui->parking_surveillance);
}

void Main_interface::on_Temperature_PushButton_clicked()
{
    // 切换到 Temperature_Curve 页面
    ui->stackedWidget->setCurrentWidget(ui->temperature_curve);
}

void Main_interface::on_Connect_PushButton_clicked()
{
    // 切换到 Car_Connect 页面
    ui->stackedWidget->setCurrentWidget(ui->car_connect);
}
